﻿using System;
using System.Collections ;
using System.Collections.Generic ;

using CommonTypes;
using BuildingBasicDomain;
using MVCFramework.Models.Controllers;

[assembly:CLSCompliant(true)]
namespace MVCFramework
{
    public interface IModel : IModelImutable, IModelExplicit
    {
        Id<IModel> Id { get; set; } 

        # region " Events Decleration "

        event EventHandler<ModelModificationEventArgs> OnAddElement;
        event EventHandler<ModelModificationEventArgs> OnRemoveElement;
        event EventHandler<ModelModificationEventArgs> OnGetElement;

        #endregion

        # region " Add, Remove , Modify Models Declearation "

        bool AddObject(IModelData _object);
        bool RemoveObject(IModelData _object);
        bool Modify(IModelData _object, Vector v);
        void RequestIdRegistration(object _object);
        object DeepCopy();

        #endregion
    }
    // No use For now 
    public interface IModelImutable : IModelDrawable
    {

        IList<IModelData> GetGroup(string name);
        IList<IModelData> GetGroup(Type type);
        bool ContainsGroup(string name);
        bool Contains(IModelData _object);
        IList<IModelData> this[string name] { get; }
        IList<IModelData> this[Type type] { get;}

    }
    //no use for now
    public interface IModelDrawable:IEnumerable,IVisitorHost
    {
        Hashtable HashTable {get ;set;}
        bool NeedsUpdate{get ;set;}  
        int MaxId { get;} 
        object GetObject(int id);
    }

    public delegate void OnModifyEventHandler(object sender, EventArgs e);
    public class ModelModificationEventArgs : EventArgs
    {
        object modified;
        object newObject;
        ModelChangeType changetype;

        public ModelChangeType Changetype
        {
            get { return changetype; }
            set { changetype = value; }
        }

        public ModelModificationEventArgs(object modified,ModelChangeType changetype )
        {
            this.modified = modified;
            this.changetype = changetype;
        }

        public ModelModificationEventArgs(object modified,object newObject, ModelChangeType changetype)
        {
            System.Diagnostics.Debug.Assert(newObject != modified, "Object dose not really changed ");
            System.Diagnostics.Debug.Assert(changetype == ModelChangeType .Changed , "Object dose not realy changed ");

            this.newObject = newObject;
            this.modified = modified;
            this.changetype = changetype;
        }

        public ModelModificationEventArgs()
        {

        }

        public object Modified
        {
            get { return modified; }
            set { modified = value; }
        }

    }

    public class ModelObjectModificationEventArgs : EventArgs
    {
     public    System.ComponentModel. PropertyDescriptor PropDescr;
        public object RefObject;
        public object OldValue;
        public object NewValue;

        public ModelObjectModificationEventArgs(System.ComponentModel.PropertyDescriptor pd, object refObject, object oldValue, object newValue)
        {
            PropDescr = pd;
            RefObject = refObject;
            OldValue = oldValue;
            NewValue = newValue;
        }


    }
    public enum ModelChangeType
    {
        Added,
        Removed,
        Changed
    }
}
